package lxx.pandams.activity;

import lxx.pandams.R;
import lxx.pandams.adapter.GridViewAdapter;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;

public class MainActivity extends Activity {

	private GridView gv_layout;
	private String[] titles;
	private int[] photoIds;
	private Context ctx;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_main);
		ctx = this;
		initUI();
		initData();
		initAction();
	}

	// 初始化控件
	private void initUI() {
		gv_layout = (GridView) findViewById(R.id.gv_layout);

	}

	// 为控件提供数据
	private void initData() {
		// initialize title
		titles = new String[] { "手机防盗", "通信卫士", "软件管理", "进程管理", "手机杀毒", "缓存清理",
				"高级工具", "设置中心" };

		// initialize photo
		photoIds = new int[] { R.drawable.home_safe,
				R.drawable.home_callmsgsafe, R.drawable.home_apps,
				R.drawable.home_taskmanager, R.drawable.home_trojan,
				R.drawable.home_sysoptimize, R.drawable.home_tools,
				R.drawable.home_settings };

		// initialize adapter for GridView
		GridViewAdapter adapter = new GridViewAdapter(ctx, titles, photoIds);
		// set content to GridView
		gv_layout.setAdapter(adapter);
	}

	// initialize action
	private void initAction() {
		gv_layout.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				switch (position) {
				case 0:

					break;
				case 1:
					Intent intent = new Intent(ctx, CommSafeActivity.class);
					startActivity(intent);
					break;
				case 2:

					break;
				case 3:

					break;
				case 4:

					break;
				case 5:

					break;
				case 6:

					break;
				case 7:
					Intent intent2 = new Intent(ctx,SettingActivity.class);
					startActivity(intent2);
					break;
				}
			}

		});
	}

}
